package com.scalar.chiptrack.sales.reports.actions;

import com.scalar.chiptrack.ChipTrackAction;
import com.scalar.chiptrack.utils.DateUtil;
import com.scalar.chiptrack.utils.ExcelUtils;
import com.scalar.chiptrack.operations.reports.DataDumpReportsHelper;
import com.scalar.chiptrack.operations.process.dao.FinishedGoodsDAO;
import com.scalar.chiptrack.operations.process.FinishedGoods;
import com.scalar.chiptrack.operations.vendor.dao.VendorDAO;
import com.scalar.chiptrack.sales.dao.NewCustomerDAO;
import com.scalar.chiptrack.sales.dao.CustomerDAO;
import com.scalar.chiptrack.sales.reports.forms.CustomerReportForm;
import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.commons.Constants;
import com.scalar.chiptrack.commons.ExcelColumnProperties;
import com.scalar.chiptrack.users.User;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.util.LabelValueBean;
import org.apache.poi.ss.usermodel.Workbook;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Srikanth.C
 * Date: Feb 20, 2007
 * Time: 12:57:25 PM
 * To change this template use File | Settings | File Templates.
 */
public class CustomerReportAction extends ChipTrackAction
{
    private static final String ACTION_NAME = "/customerReport.do";
    public ActionForward execute( ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response )
            throws Exception
    {

        String action = request.getParameter( "action" );
        HttpSession session = request.getSession();

        User user = ( User ) session.getAttribute( SessionKeys.USER_KEY );

        if( user == null )
        {
            session.setAttribute( SessionKeys.SOURCE_PAGE_KEY, ACTION_NAME + "?" + request.getQueryString() );
            return ( mapping.findForward( "login" ) );
        }

        CustomerReportForm customerReportForm = ( CustomerReportForm ) form;
        ArrayList<LabelValueBean> customerTypeList   = null;
        ArrayList<LabelValueBean> customerList   = null;
        ArrayList<String> regionList = null;
        ArrayList<LabelValueBean> statusList = null;
        ArrayList customerDetailsList = null;
        Workbook workbook = null;
        String fileName = "";

        ExcelColumnProperties colProps1 = new ExcelColumnProperties("EXTENDED PRICE");
        colProps1.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);
        colProps1.setShowTotal(true);
        ExcelColumnProperties colProps2 = new ExcelColumnProperties("UNIT PRICE");
        colProps2.setCellStyle(ExcelColumnProperties.CELL_STYLE_CURRENCY_$);

        List<ExcelColumnProperties> list = new ArrayList<ExcelColumnProperties>();
        list.add(colProps1);
        list.add(colProps2);

        String customerType = request.getParameter( "customerType" );

        if ( action == null )
        {
            action = "";
        }
        try
        {
            if ( "customerReport".equalsIgnoreCase(action) || "".equals(action) )
            {
                try
                {
                    customerReportForm.setCustomer("0");
                    customerTypeList = NewCustomerDAO.loadCustomerType();

                    if ( "0".equalsIgnoreCase(customerType) || customerType == null )
                    {
                        customerList     = new ArrayList<LabelValueBean>();
                    }
                    else
                    {
                        customerList = NewCustomerDAO.getAllCustomerNamesByCustomerType( customerType );
                    }
                    regionList = CustomerDAO.getAllRegionNames();
                    statusList = getCustomerStatus();

                }
                catch( Exception e )
                {
                    customerTypeList     = new ArrayList<LabelValueBean>();
                    customerList         = new ArrayList<LabelValueBean>();
                    regionList           = new ArrayList<String>();
                    statusList           = new ArrayList<LabelValueBean>();

                    e.printStackTrace();
                }
                request.setAttribute( "customerTypeList", customerTypeList );
                request.setAttribute( "customerList", customerList );
                request.setAttribute( "regionList", regionList );
                request.setAttribute( "statusList", statusList );

            }
            else if ( "customerARReport".equalsIgnoreCase(action) )
            {
                request.setAttribute("customerList", CustomerDAO.getAllCustomerNamesNoStringsAttached() );
            }
            else if( "pendingShipment".equalsIgnoreCase(action) )
            {
                ArrayList partNumberList   = null;
                ArrayList<LabelValueBean> vendorList   = null;

                //customerList = NewCustomerDAO.getAllCustomerNamesByCustomerType( "customer" );
                customerList = CustomerDAO.getAllCustomerNamesByUserType (null,user);
                if ( user.getUserType() == Constants.USER_TYPE_CUSTOMER )
                {
                    customerReportForm.setCustomer(user.getCustomerId()+"");
                }

                partNumberList = FinishedGoodsDAO.loadFinishedGoods();

                ArrayList<LabelValueBean> mktgPartNumberSelectList = new ArrayList<LabelValueBean>();
                FinishedGoods finishedGoods = null;
              
                for( int i = 0; i < partNumberList.size(); i++ )
                {
                    finishedGoods = ( FinishedGoods ) partNumberList.get( i );
                    mktgPartNumberSelectList.add( new LabelValueBean (finishedGoods.getManufacturingPartNo(), finishedGoods.getProductId()+""));
                }

                vendorList = VendorDAO.getVendorNamesByProcessByUserType( null,Constants.LOCATION_TYPE_FG,user );
                
                request.setAttribute( "customerList", customerList );
                request.setAttribute( "vendorList", vendorList );
                request.setAttribute( "mktgPartNumberSelectList", mktgPartNumberSelectList );
            }
            else if ( action.endsWith( "xls" ) )
            {
                if ( "generatexls".equalsIgnoreCase(action) )
                {
                    customerType    = request.getParameter( "prompt0" );
                    String customer = request.getParameter( "prompt1" );
                    String region   = request.getParameter( "prompt2" );
                    String status   = request.getParameter( "prompt3" );
                    String defaultPrompt= request.getParameter( "prompt4" );

                    customerDetailsList = NewCustomerDAO.getCustomerDetails( null,customerType,customer,region,status,defaultPrompt);

                    workbook =  DataDumpReportsHelper.getWorkbook( customerDetailsList, "Customer Report", null, null, null );
                    fileName = "CustomerReport_" + DateUtil.getTimeStamp() ;
                }
                else if ( "cobacklogxls".equalsIgnoreCase(action) )
                {
                   //@PRODUCT_ID ,@SO_NUMBER ,@CUSTOMER_ID ,@SALES_PERSON ,@ASOFDATE ,@BACKLOG_TYPE ,@DEFAULTPROMPT ,@CATEGORY,@BY_PERIOD,@ORDER_TYPE

                    Map<String, String> paramMap = new HashMap<String, String>();
                    paramMap.put ( "productId", request.getParameter( "prompt0" ) );
                    paramMap.put ( "soNumber", request.getParameter( "prompt1" ) );
                    paramMap.put ( "customerId", request.getParameter( "prompt2" ) );
                    paramMap.put ( "salesPerson", request.getParameter( "prompt3" ) );
                    paramMap.put ( "asOfDate", request.getParameter( "prompt4" ) );
                    paramMap.put ( "backlogType", request.getParameter( "prompt5" ) );
                    paramMap.put ( "orderType", request.getParameter( "prompt6" ) );
                    paramMap.put ( "category", request.getParameter( "prompt7" ) );
                    paramMap.put ( "defaultPrompt", request.getParameter( "prompt8" ) );
                    paramMap.put ( "byPeriod", request.getParameter( "prompt9" ) );
                    paramMap.put ( "region", request.getParameter( "prompt11" ) );
                    paramMap.put ( "reportType", request.getParameter( "prompt10" ) );
                    paramMap.put ( "endUser", request.getParameter( "prompt12" ) );

                   workbook = NewCustomerDAO.loadBacklogReprot ( null, paramMap );
                   fileName = "BacklogReport_" + DateUtil.getTimeStamp();
                }
                else if ( "bookingxls".equalsIgnoreCase(action))
                {                     
                   //fromdate,todate,customers,products,region,repoffices,enduser,sperson,defaultPrompt,booking,orderType
                    Map<String, String> paramMap = new HashMap<String, String>();
                    paramMap.put ( "fromdate", request.getParameter( "prompt0" ) );
                    paramMap.put ( "todate", request.getParameter( "prompt1" ) );
                    paramMap.put ( "customers", request.getParameter( "prompt2" ) );
                    paramMap.put ( "products", request.getParameter( "prompt3" ) );
                    paramMap.put ( "region", request.getParameter( "prompt4" ) );
                    paramMap.put ( "repoffices", request.getParameter( "prompt5" ) );
                    paramMap.put ( "endCustomer", request.getParameter( "prompt6" ) );
                    paramMap.put ( "sperson", request.getParameter( "prompt7" ) );
                    paramMap.put ( "defaultPrompt", request.getParameter( "prompt8" ) );
                    paramMap.put ( "bookingType", request.getParameter( "prompt9" ) );
                    paramMap.put ( "orderType", request.getParameter( "prompt10" ) );
                    paramMap.put ( "endUser", request.getParameter( "prompt11" ) );
                    paramMap.put ( "period", request.getParameter( "prompt12" ) );
                    paramMap.put ( "reportType", request.getParameter( "prompt13" ) );

                   workbook = NewCustomerDAO.loadSalesBookingReprot ( null, paramMap );
                   fileName = "BookingReport_" + DateUtil.getTimeStamp() ;
                }
                else if ( "delinquentxls".equalsIgnoreCase(action))
                {
                   int orderTypeInt = -1;
                   ArrayList DeliquentList   = null;
                   //fromdate,todate,customers,products,region,repoffices,enduser,sperson,defaultPrompt,booking,orderType
                   String fromdate  = request.getParameter( "prompt0" );
                   String todate  = request.getParameter( "prompt1" );
                   String customers  = request.getParameter( "prompt2" );
                   String products  = request.getParameter( "prompt3" );
                   String region  = request.getParameter( "prompt4" );
                   String repoffices  = request.getParameter( "prompt5" );
                   String enduser  = request.getParameter( "prompt6" );
                   String sperson  = request.getParameter( "prompt7" );
                   String defaultPrompt  = request.getParameter( "prompt8" );
                   String bookingType  = request.getParameter( "prompt9" );
                   String orderType  = request.getParameter( "prompt10" );
                   String endCustomer  = request.getParameter( "prompt11" );
                   String period  = request.getParameter( "prompt12" );
                   String reportType  = request.getParameter( "prompt13" );

                   orderTypeInt = Integer.parseInt(orderType);
                   DeliquentList = NewCustomerDAO.loadSalesDeliquentReprot ( null,fromdate,todate,customers,products,region,repoffices,enduser,sperson,defaultPrompt,bookingType,orderTypeInt,endCustomer,period,reportType);
                   workbook =  DataDumpReportsHelper.getWorkbook( DeliquentList, "Sales Deliquent Report", fromdate, todate, list );
                   fileName = "Sales DeliquentReport_" + DateUtil.getTimeStamp() ;
                }
                else if ( "cancelxls".equalsIgnoreCase(action))
                {
                   int orderTypeInt = -1;
                   ArrayList CancellationList   = null;
                   //fromdate,todate,customers,products,region,repoffices,enduser,sperson,defaultPrompt,booking,orderType
                   String fromdate  = request.getParameter( "prompt0" );
                   String todate  = request.getParameter( "prompt1" );
                   String customers  = request.getParameter( "prompt2" );
                   String products  = request.getParameter( "prompt3" );
                   String region  = request.getParameter( "prompt4" );
                   String repoffices  = request.getParameter( "prompt5" );
                   String enduser  = request.getParameter( "prompt6" );
                   String sperson  = request.getParameter( "prompt7" );
                   String defaultPrompt  = request.getParameter( "prompt8" );
                   String bookingType  = request.getParameter( "prompt9" );
                   String orderType  = request.getParameter( "prompt10" );
                   String endCustomer  = request.getParameter( "prompt11" );
                   String period  = request.getParameter( "prompt12" );
                   String reportType  = request.getParameter( "prompt13" );

                   orderTypeInt = Integer.parseInt(orderType);
                   CancellationList = NewCustomerDAO.loadSalesCancellationReprot ( null,fromdate,todate,customers,products,region,repoffices,enduser,sperson,defaultPrompt,bookingType,orderTypeInt,endCustomer,period,reportType);
                   workbook =  DataDumpReportsHelper.getWorkbook( CancellationList, "Sales Cancellation Report", fromdate, todate, list );
                   fileName = "CancellationReport_" + DateUtil.getTimeStamp() ;
                }
                else if ( "holdxls".equalsIgnoreCase(action))
                {
                   int orderTypeInt = -1;
                   ArrayList HoldList   = null;
                   //fromdate,todate,customers,products,region,repoffices,enduser,sperson,defaultPrompt,booking,orderType
                   String fromdate  = request.getParameter( "prompt0" );
                   String todate  = request.getParameter( "prompt1" );
                   String customers  = request.getParameter( "prompt2" );
                   String products  = request.getParameter( "prompt3" );
                   String region  = request.getParameter( "prompt4" );
                   String repoffices  = request.getParameter( "prompt5" );
                   String enduser  = request.getParameter( "prompt6" );
                   String sperson  = request.getParameter( "prompt7" );
                   String defaultPrompt  = request.getParameter( "prompt8" );
                   String bookingType  = request.getParameter( "prompt9" );
                   String orderType  = request.getParameter( "prompt10" );
                   String endCustomer  = request.getParameter( "prompt11" );
                   String period  = request.getParameter( "prompt12" );
                   String reportType  = request.getParameter( "prompt13" );

                   orderTypeInt = Integer.parseInt(orderType);
                   HoldList = NewCustomerDAO.loadSalesHoldReprot ( null,fromdate,todate,customers,products,region,repoffices,enduser,sperson,defaultPrompt,bookingType,orderTypeInt,endCustomer,period,reportType);
                   workbook =  DataDumpReportsHelper.getWorkbook( HoldList, "Sales Hold Report", fromdate, todate, null );
                   fileName = "SalesHoldReport_" + DateUtil.getTimeStamp() ;
                }
                else if ( "shipmentxls".equalsIgnoreCase(action))
                {
                   int orderTypeInt = -1;
                   ArrayList ShipmentList   = null;

                   String product  = request.getParameter( "prompt0" );
                   String salesorderno  = request.getParameter( "prompt1" );
                   String customer  = request.getParameter( "prompt2" );
                   String datefrom  = request.getParameter( "prompt3" );
                   String dateto  = request.getParameter( "prompt4" );
                   String orderType  = request.getParameter( "prompt5" );
                   String period  = request.getParameter( "prompt6" );
                   String reportType  = request.getParameter( "prompt7" );
                   String defaultPrompt  = request.getParameter( "prompt8" );

                   orderTypeInt = Integer.parseInt(orderType);
                   ShipmentList = NewCustomerDAO.loadShipmentReprot ( null,product,salesorderno,customer,datefrom,dateto,orderTypeInt,period,reportType,defaultPrompt);
                   workbook =  DataDumpReportsHelper.getWorkbook( ShipmentList, "Shipment Report", datefrom, dateto, list );
                   fileName = "Sales ShipmentReport_" + DateUtil.getTimeStamp() ;
                }
                else if ( "pendingShipmentxls".equalsIgnoreCase(action))
                {
                   int orderTypeInt = -1;
                   ArrayList ShipmentList   = null;

                   String customer  = request.getParameter( "prompt0" );
                   String product  = request.getParameter( "prompt1" );
                   String salesorderno  = request.getParameter( "prompt2" );
                   String orderType  = request.getParameter( "prompt3" );
                   String dateRange  = request.getParameter( "prompt4" );
                   String reportType  = request.getParameter( "prompt5" );
                   String vendor  = request.getParameter( "prompt6" );
                   String defaultPrompt  = request.getParameter( "prompt7" );

                   orderTypeInt = Integer.parseInt(orderType);
                   ShipmentList = NewCustomerDAO.loadPendingShipmentReprot ( null,customer,product,salesorderno,orderTypeInt,dateRange,reportType,vendor,defaultPrompt);
                   workbook =  DataDumpReportsHelper.getWorkbook( ShipmentList, "Pending Shipment Report", null, null, null );
                   fileName = "PendingShipmentReport_" + DateUtil.getTimeStamp() ;
                }
                else if ( "performancexls".equalsIgnoreCase(action))
                {
                   String fromDate  = request.getParameter( "prompt0" );
                   String toDate  = request.getParameter( "prompt1" );
                   String productIds  = request.getParameter( "prompt2" );
                   String customerId  = request.getParameter( "prompt3" );
                   String orderType  = request.getParameter( "prompt4" );
                   String reportType  = request.getParameter( "prompt5" );
                   String defaultPrompt  = request.getParameter( "prompt6" );

                   /*ShipmentList = NewCustomerDAO.loadPerformanceReport ( null,fromDate,toDate,productIds,customerId,orderTypeInt,reportType,defaultPrompt);
                   workbook =  DataDumpReportsHelper.getWorkbook( ShipmentList, "Performance Report" );*/
                    Map<String, String> paramMap = new HashMap<String, String>();
                    paramMap.put ( "fromDate", fromDate );
                    paramMap.put ( "toDate", toDate );
                    paramMap.put ( "productIds", productIds );
                    paramMap.put ( "customerId", customerId );
                    paramMap.put ( "orderType",orderType );
                    paramMap.put ( "reportType", reportType );
                    paramMap.put ( "defaultPrompt", defaultPrompt );
                    workbook =  NewCustomerDAO.loadPerformanceReportWorkbook( null,paramMap );
                    fileName = "PerformanceReport_" + DateUtil.getTimeStamp() ;
                }
                else if ( "customerARReportxls".equalsIgnoreCase(action) )
                {
                    Map<String, String> paramMap = new HashMap<String, String>();
                    paramMap.put("customerId", customerReportForm.getCustomerId()+"" );
                    workbook = NewCustomerDAO.loadCustomerARReprot( null, paramMap);
                    fileName = "CustomerARReport_" + DateUtil.getTimeStamp() ;
                }
                else if ( "billingxls".equalsIgnoreCase(action))
                {
                    Map<String, String> paramMap = new HashMap<String, String>();
                    paramMap.put ( "product", request.getParameter( "prompt0" ) );
                    paramMap.put ( "salesorderno", request.getParameter( "prompt1" ) );
                    paramMap.put ( "customer", request.getParameter( "prompt2" ) );
                    paramMap.put ( "salesPerson", request.getParameter( "prompt3" ) );
                    paramMap.put ( "datefrom", request.getParameter( "prompt4" ) );
                    paramMap.put ( "dateto", request.getParameter( "prompt5" ) );
                    paramMap.put ( "orderType", request.getParameter( "prompt6" ) );
                    paramMap.put ( "period", request.getParameter( "prompt7" ) );
                    paramMap.put ( "reportType", request.getParameter( "prompt8" ) );
                    paramMap.put ( "region", request.getParameter( "prompt10" ) );
                    paramMap.put ( "defaultPrompt", request.getParameter( "prompt9" ) );
                    paramMap.put ( "endUser", request.getParameter( "prompt11" ) );

                   workbook = NewCustomerDAO.loadBillingReprot ( null, paramMap );
                   fileName = "BillingReport_" + DateUtil.getTimeStamp() ;
                }
                else if ( "newEndUserxls".equalsIgnoreCase(action))
                {
                   ArrayList newEndUsersList = NewCustomerDAO.loadNewEndUsersReprotByCustomer ( null);
                   workbook =  DataDumpReportsHelper.getWorkbook( newEndUsersList, "New End Users Report", null, null, null );
                   fileName = "NewEndUsersReport_" + DateUtil.getTimeStamp() ;
                }
                else if ( "newEndCustomersxls".equalsIgnoreCase(action))
                {
                   ArrayList newEndCustomersList = NewCustomerDAO.loadnewEndCustomersReprotByCustomer ( null);
                   workbook =  DataDumpReportsHelper.getWorkbook( newEndCustomersList, "New End Customers Report", null, null, null );
                   fileName = "newEndCustomersReport_" + DateUtil.getTimeStamp() ;
                }
                else if ( "newEndUserEndCustomersxls".equalsIgnoreCase(action))
                {
                   ArrayList newEndUserEndCustomersList = NewCustomerDAO.loadNewEndUserEndCustomersReprotByCustomer ( null);
                   workbook =  DataDumpReportsHelper.getWorkbook( newEndUserEndCustomersList, "New End User End Customers", null, null, null );
                   fileName = "newEndUserEndCustomersReport_"+DateUtil.getTimeStamp();
                }

                ExcelUtils.generateExcelReport( workbook, fileName, response );
			}
            else if ( action.endsWith( "csv" ) )
            {
                String csvString = "";
                if ( "bookingcsv".equalsIgnoreCase( action ) )
                {
                    int orderTypeInt = -1;
                    String fromdate  = request.getParameter( "prompt0" );
                    String todate  = request.getParameter( "prompt1" );
                    String customers  = request.getParameter( "prompt2" );
                    String products  = request.getParameter( "prompt3" );
                    String region  = request.getParameter( "prompt4" );
                    String repoffices  = request.getParameter( "prompt5" );
                    String enduser  = request.getParameter( "prompt6" );
                    String sperson  = request.getParameter( "prompt7" );
                    String defaultPrompt  = request.getParameter( "prompt8" );
                    String bookingType  = request.getParameter( "prompt9" );
                    String orderType  = request.getParameter( "prompt10" );
                    String endCustomer  = request.getParameter( "prompt11" );
                    String period  = request.getParameter( "prompt12" );
                    String reportType  = request.getParameter( "prompt13" );
                    orderTypeInt = Integer.parseInt(orderType);

                    csvString = NewCustomerDAO.loadSalesBookingReportCSV ( null,fromdate,todate,customers,products,region,repoffices,enduser,sperson,defaultPrompt,bookingType,orderTypeInt,endCustomer,period,reportType);
                    fileName = "BookingReport_" + DateUtil.getTimeStamp() + ".csv";
                }
                else if ( "delinquentcsv".equalsIgnoreCase(action))
                {
                   int orderTypeInt = -1;
                   ArrayList DeliquentList   = null;
                   String fromdate  = request.getParameter( "prompt0" );
                   String todate  = request.getParameter( "prompt1" );
                   String customers  = request.getParameter( "prompt2" );
                   String products  = request.getParameter( "prompt3" );
                   String region  = request.getParameter( "prompt4" );
                   String repoffices  = request.getParameter( "prompt5" );
                   String enduser  = request.getParameter( "prompt6" );
                   String sperson  = request.getParameter( "prompt7" );
                   String defaultPrompt  = request.getParameter( "prompt8" );
                   String bookingType  = request.getParameter( "prompt9" );
                   String orderType  = request.getParameter( "prompt10" );
                   String endCustomer  = request.getParameter( "prompt11" );
                   String period  = request.getParameter( "prompt12" );
                   String reportType  = request.getParameter( "prompt13" );

                   orderTypeInt = Integer.parseInt(orderType);
                   csvString = NewCustomerDAO.loadSalesDeliquentReportCSV ( null,fromdate,todate,customers,products,region,repoffices,enduser,sperson,defaultPrompt,bookingType,orderTypeInt,endCustomer,period,reportType);
                   fileName = "DeliquentReport_"+DateUtil.getTimeStamp()+".csv";
                }
                else if ( "cancelcsv".equalsIgnoreCase(action))
                {
                   int orderTypeInt = -1;
                   ArrayList CancellationList   = null;
                   //fromdate,todate,customers,products,region,repoffices,enduser,sperson,defaultPrompt,booking,orderType
                   String fromdate  = request.getParameter( "prompt0" );
                   String todate  = request.getParameter( "prompt1" );
                   String customers  = request.getParameter( "prompt2" );
                   String products  = request.getParameter( "prompt3" );
                   String region  = request.getParameter( "prompt4" );
                   String repoffices  = request.getParameter( "prompt5" );
                   String enduser  = request.getParameter( "prompt6" );
                   String sperson  = request.getParameter( "prompt7" );
                   String defaultPrompt  = request.getParameter( "prompt8" );
                   String bookingType  = request.getParameter( "prompt9" );
                   String orderType  = request.getParameter( "prompt10" );
                   String endCustomer  = request.getParameter( "prompt11" );
                   String period  = request.getParameter( "prompt12" );
                   String reportType  = request.getParameter( "prompt13" );

                   orderTypeInt = Integer.parseInt(orderType);
                   csvString = NewCustomerDAO.loadSalesCancellationReportCSV ( null,fromdate,todate,customers,products,region,repoffices,enduser,sperson,defaultPrompt,bookingType,orderTypeInt,endCustomer,period,reportType);
                   fileName = "CancellationReport_"+DateUtil.getTimeStamp()+".csv";
                }
                else if ( "holdcsv".equalsIgnoreCase(action))
                {
                   int orderTypeInt = -1;
                   ArrayList HoldList   = null;
                   String fromdate  = request.getParameter( "prompt0" );
                   String todate  = request.getParameter( "prompt1" );
                   String customers  = request.getParameter( "prompt2" );
                   String products  = request.getParameter( "prompt3" );
                   String region  = request.getParameter( "prompt4" );
                   String repoffices  = request.getParameter( "prompt5" );
                   String enduser  = request.getParameter( "prompt6" );
                   String sperson  = request.getParameter( "prompt7" );
                   String defaultPrompt  = request.getParameter( "prompt8" );
                   String bookingType  = request.getParameter( "prompt9" );
                   String orderType  = request.getParameter( "prompt10" );
                   String endCustomer  = request.getParameter( "prompt11" );
                   String period  = request.getParameter( "prompt12" );
                   String reportType  = request.getParameter( "prompt13" );

                   orderTypeInt = Integer.parseInt(orderType);
                   csvString = NewCustomerDAO.loadSalesHoldReportCSV ( null,fromdate,todate,customers,products,region,repoffices,enduser,sperson,defaultPrompt,bookingType,orderTypeInt,endCustomer,period,reportType);
                   fileName = "HoldReport_"+DateUtil.getTimeStamp()+".csv";
                }
                else if ( "shipmentcsv".equalsIgnoreCase(action))
                {
                   int orderTypeInt = -1;

                   String product  = request.getParameter( "prompt0" );
                   String salesorderno  = request.getParameter( "prompt1" );
                   String customer  = request.getParameter( "prompt2" );
                   String datefrom  = request.getParameter( "prompt3" );
                   String dateto  = request.getParameter( "prompt4" );
                   String orderType  = request.getParameter( "prompt5" );
                   String period  = request.getParameter( "prompt6" );
                   String reportType  = request.getParameter( "prompt7" );
                   String defaultPrompt  = request.getParameter( "prompt8" );

                   orderTypeInt = Integer.parseInt(orderType);
                   csvString = NewCustomerDAO.loadShipmentReportCSV ( null,product,salesorderno,customer,datefrom,dateto,orderTypeInt,period,reportType,defaultPrompt);
                   fileName = "ShipmentReport_" + DateUtil.getTimeStamp() + ".csv";
                }

                ExcelUtils.generateCSVReport( csvString, fileName, response);
                
                return null;
            }
        }
        catch ( Exception e)
        {
            //errors.put ( "Could not generate excel file", null );
            e.printStackTrace();
        }

        if( "customerReport".equalsIgnoreCase(action) )
        {
            return ( mapping.findForward( "customerReport" ) );
        }
        else if( "customerARReport".equalsIgnoreCase(action) )
        {
            return ( mapping.findForward( "customerARReport" ) );
        }
        else if( "pendingShipment".equalsIgnoreCase(action) )
        {
            return ( mapping.findForward( "pendingShipment" ) );
        }
        else
        {
            return mapping.findForward( "reportView" );
        }

        //return null;
    }

    public ArrayList<LabelValueBean> getCustomerStatus()
    {
        ArrayList<LabelValueBean> statusList = new ArrayList<LabelValueBean>();

        statusList.add( new LabelValueBean("Active","Active"));
        statusList.add( new LabelValueBean("Disable","Disable"));

        return  statusList;
    }
}
